﻿<?php
class CompanysAction extends GlobalAction
{
   
    public function index()
    {
		
		
		import("ORG.Util.Page");
		//平台帮助
		$list_rec_help = parent::rec_help();
		$this->assign('list_rec_help',$list_rec_help);
		//推荐公司
		$list_rec_company = parent::rec_company();
		$this->assign('list_rec_company',$list_rec_company);
		
		//新闻类分页
		
		$keyword = $_REQUEST['keyword'];
		$condition ='';
		if($keyword != ''){$condition .= "company_name like '\%$keyword\%' and ";}
        $condition .=' 1=1';
		$dao = M('company');
		$total = $dao->where($condition)->count();
        $page = new Page($total,6);
		 //如果有参数
		 //$page->parameter = '&keyword=ff&zc_id=1';
         $list=$dao->where($condition)->limit($page->firstRow.",".$page->listRows)->select();
		 foreach($list as $k=>$v){
		//产品数
		$list[$k]['product_num'] = M('products')->where('company_id='.$v['id'])->count();
		$list[$k]['person_num'] = M('company_user')->where('company_id='.$v['id'])->count();
		
		}
	
         $show = $page ->show();
		 $this->assign('list',$list);
		 $this -> assign('page',$show); // 赋值分页输出
		
		$list_hot = self::hot_news(10,'hot');
		
		 $this->assign('list_hot',$list_hot);
		 
		
        $this->display();
    }

function hot_news($num=10,$type){
	
	if($type =='hot')
	{
		$orders ='counts desc';
	}
	elseif($type =='new')
	{
		$orders ='news_id desc';
	}
	else
	{
		$orders ='';
	}
	$list = M('company_news')->order($orders)->limit($num)->select();
	return $list;
	}

}
?>